/*******************************************************************
 *         Advanced 3D Game Programming using DirectX 9.0
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * copyright (c) 2003 by Peter A Walsh and Adrian Perez
 * See license.txt for modification and distribution information
 ******************************************************************/

#ifndef _POLYGON2_H
#define _POLYGON2_H

#include <stdlib.h>
#include "point2.h"
#include "texture.h"
#include "rect.h"

struct Polygon2 
{
	int nElem; // number of elements in the polygon
	int maxElem;
	int layer;

	Point2** pList;
	Point2* position;
	Texture* texture;
	Rect* box;

	Polygon2()
	{
		nElem = 0;
		maxElem = 0;
		pList = NULL;
		position =NULL;
		texture =NULL;
		box =NULL;
	}

	~Polygon2()
	{
		DestroyData();
	}

	Polygon2( int maxSize )
	{
		int i;
		nElem = 0;
		maxElem = maxSize;
		pList = new Point2*[maxSize];

		for(i=0; i<maxSize; i++){

			pList[i] =new Point2;
		}
		position =NULL;
		texture =NULL;
		box =NULL;
	}
/*
	Polygon2( const Polygon2 &in )
	{
		CloneData( in );
	}

	void CloneData( const Polygon2 &in )
	{
		if( !in.pList ) 
			return;

		pList = new Point2[in.maxElem];
		maxElem = in.maxElem;
		nElem = in.nElem;
		for( int i=0; i<in.nElem; i++ )
		{
			pList[i] = in.pList[i];
		}
	}

	Polygon2& operator=( const Polygon2 &in )
	{
		if( &in != this )
		{
			DestroyData();

			CloneData( in );
		}
		
		return *this;
	}
	*/
	void DestroyData( )
	{
		int i;
		if( pList )
		{
			for(i=0; i<nElem; i++){
				delete pList[i];
				pList[i] =NULL;
			}

			delete[] pList;
		}
		pList = NULL;

		delete position;
		position =NULL;
		delete texture;
		texture =NULL;
		delete box;
		box =NULL;
	}

};

#endif /*_POLYGON2_H*/